package com.jiuzhou.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jiuzhou.common.log.annotation.Log;
import com.jiuzhou.common.log.enums.BusinessType;
import com.jiuzhou.common.security.annotation.PreAuthorize;
import com.jiuzhou.system.domain.SysCustomerPage;
import com.jiuzhou.system.service.ISysCustomerPageService;
import com.jiuzhou.common.core.web.controller.BaseController;
import com.jiuzhou.common.core.web.domain.AjaxResult;
import com.jiuzhou.common.core.utils.poi.ExcelUtil;
import com.jiuzhou.common.core.web.page.TableDataInfo;

/**
 * 自定义表单Controller
 *
 * @author jiuzhou
 * @date 2021-08-24
 */
@RestController
@RequestMapping("/page")
public class SysCustomerPageController extends BaseController {
    @Autowired
    private ISysCustomerPageService sysCustomerPageService;

    /**
     * 查询自定义表单列表
     */
    @PreAuthorize(hasPermi = "system:page:list")
    @GetMapping("/list")
    public TableDataInfo list(SysCustomerPage sysCustomerPage) {
        startPage();
        List<SysCustomerPage> list = sysCustomerPageService.selectSysCustomerPageList(sysCustomerPage);
        return getDataTable(list);
    }

    /**
     * 导出自定义表单列表
     */
    @PreAuthorize(hasPermi = "system:page:export")
    @Log(title = "自定义表单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCustomerPage sysCustomerPage) throws IOException {
        List<SysCustomerPage> list = sysCustomerPageService.selectSysCustomerPageList(sysCustomerPage);
        ExcelUtil<SysCustomerPage> util = new ExcelUtil<SysCustomerPage>(SysCustomerPage.class);
        util.exportExcel(response, list, "自定义表单数据");
    }

    /**
     * 获取自定义表单详细信息
     */
    @PreAuthorize(hasPermi = "system:page:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysCustomerPageService.selectSysCustomerPageById(id));
    }

    /**
     * 新增自定义表单
     */
    @PreAuthorize(hasPermi = "system:page:add")
    @Log(title = "自定义表单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCustomerPage sysCustomerPage) {
        return toAjax(sysCustomerPageService.insertSysCustomerPage(sysCustomerPage));
    }

    /**
     * 修改自定义表单
     */
    @PreAuthorize(hasPermi = "system:page:edit")
    @Log(title = "自定义表单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCustomerPage sysCustomerPage) {
        return toAjax(sysCustomerPageService.updateSysCustomerPage(sysCustomerPage));
    }

    /**
     * 删除自定义表单
     */
    @PreAuthorize(hasPermi = "system:page:remove")
    @Log(title = "自定义表单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysCustomerPageService.deleteSysCustomerPageByIds(ids));
    }
}
